%% interpolateFFT
% 
% This function interpolates 
%
%% Synatax
% [ Flow ] = interpolateFFT( Flow, Pressure )
%
%% Description
% This function will take in data from pressure and flow extraction/fitting
% and run the fouier decompostion. The output of this function will be the
% fourier harmonics and amplitude and phase. Set plot_type to string of
% 'Pressure' for the pressure fft output and 'Flow' for the flow fft
%  output.
%
%% Arguments
%* Flow                         - Double: A nx1 double of the
%                                         pressure data
%
%* Pressure                                 - Double: A nx1 double of time data
%
%
%% Returns
%
%* Flow                          - struct: A nx6 double of
%                                         freqeuncy, 
%                                         freq(m) =  frequency components
%                                         a0 = DC offset
%                                         an = amplitude of the consines (real part, rec corrdinates)
%                                         bn = amplitude of the sines (imaginary part, rec corrdinates)
%                                         amp = amp (polar)
%                                         phase_m = phase (polar)
%
%% Function Side Effects
%* The Flow structure has an additional field FFT_Interp added
%
%% Exceptions
%* N/A
%
%% See Also
%* N/A
 
function [ Flow ] = interpolateFFT( Flow, Pressure )

Flow.FFT_Interp = Flow.FFT_Outputs;

% Obtain pressure frequency
pressureFrequency = Pressure.FFT_Outputs(:, 1);

% Interpolate flow FFT using frequency data from pressure FFT

flowFrequency = Flow.FFT_Outputs(:, 1);
flowAmplitude = Flow.FFT_Outputs(:, 4);
flowPhase = Flow.FFT_Outputs(:, 5);

freqAndAmplitude = fit(flowFrequency, flowAmplitude, 'linearinterp');
Flow.FFT_Interp(:, 4) = feval(freqAndAmplitude, pressureFrequency);

freqAndPhase = fit(flowFrequency, flowPhase, 'linearinterp');
Flow.FFT_Interp(:, 5) = feval(freqAndPhase, pressureFrequency);

